<template>
  <div class="app-container">
    <div class="search-container">
      <el-form :model="searchParam" :inline="true">
        <el-form-item label="采集时间">
          <el-date-picker
            v-model="searchParam.createTimeSearch"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="YYYY-MM-DD HH:mm:ss"
            @change="getcreateTime"
          />
        </el-form-item>
        <el-form-item label="处理状态">
          <el-select
            v-model="searchParam.postgresStatus"
            placeholder="请选择处理状态"
            clearable
          >
            <el-option
              v-for="item in useDictionary('FileReadStatus')"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="数据类型">
          <el-select
            v-model="searchParam.dataType"
            placeholder="请选择数据类型"
            clearable
          >
            <el-option
              v-for="item in useDictionary('postgresDataType')"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search"
            ><i-ep-search />搜索</el-button
          >
          <el-button @click="reset"><i-ep-refresh />重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <template #header> </template>

      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          label="采集时间"
          prop="createTime"
          min-width="170"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column
          label="检具编号"
          prop="cubingCode"
          min-width="130"
          show-overflow-tooltip
        />
        <el-table-column
          label="读取主键记录"
          prop="idIndex"
          min-width="130"
          show-overflow-tooltip
        />
        <el-table-column
          label="数据表"
          prop="postgresTableName"
          min-width="150"
          show-overflow-tooltip
        />
        <el-table-column
          label="数据类型"
          prop="dataType"
          min-width="120"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            {{ scope.row.dataType === "1" ? "检具特性数据" : "检测质量数据" }}
          </template>
        </el-table-column>
        <el-table-column
          label="上次更新时间"
          prop="lastUpdatedTime"
          min-width="170"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column
          label="处理状态"
          prop="postgresStatus"
          min-width="100"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            <el-tag :type="scope.row.postgresStatus ? 'success' : 'danger'">
              {{ scope.row.postgresStatus ? "成功" : "失败" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="处理信息"
          prop="postgresHandleMess"
          min-width="450"
          show-overflow-tooltip
        />
      </el-table>

      <el-pagination
        :background="true"
        :current-page="pageable.pageNum"
        :page-size="pageable.pageSize"
        :page-sizes="[10, 25, 50, 100]"
        :total="pageable.total"
        layout="total, sizes, prev, pager, next, jumper"
        class="mt-[20px]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { useTable, useDownload, useDictionary } from "@/utils/useTable";
import request from "@/utils/request";

defineOptions({
  name: "ETLQDPOSTGRESCOLLECTRECORD",
  inheritAttrs: false,
});

// 请求参数
const requestApi = "/pqd-etl/qdpostgrescollectrecord/queryByPage";

// 是否需要分页
const pagination = true;

const initParam = {};

// 初始化搜索参数数据
const searchParamInit = {
  createTimeSearch: [],
  createTimeStart: "",
  createTimeEnd: "",
  postgresStatus: "",
  dataType: "",
};

const deleteParam = {
  api: "/pqd-etl/qdpostgrescollectrecord/delete",
  data: {},
};

// 数据请求错误后处理
function requestError() {}

const dataCallBack = ref(undefined); // 无需二次数据处理&不传赞数也行

// 表格操作 Hooks
const {
  tableData,
  pageable,
  searchParam,
  ids,
  getTableList,
  search,
  reset,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  handleTableDelete,
  loading,
}: any = useTable(
  requestApi,
  initParam,
  searchParamInit,
  pagination,
  dataCallBack.value,
  requestError,
  deleteParam
);

onMounted(() => {
  getTableList();
});

function getcreateTime(data: any) {
  if (data) {
    searchParam.value.createTimeStart = data[0];
    searchParam.value.createTimeEnd = data[1];
  } else {
    searchParam.value.createTimeStart = "";
    searchParam.value.createTimeEnd = "";
  }
}
</script>
